﻿using System;

namespace TextEditor
{
    public class ZYTextParagraph : ZYTextElement
    {

        /***
         * 构造函数
         */
        public ZYTextParagraph(ParagraphAlignConst _align)
        {
            this.Align = _align;
        }

        public ZYTextParagraph()
        {

        }

        private new bool Visible = true;
        public bool IsVisible
        {
            get { return Visible; }
            set { Visible = value; }
        }

        public override string GetXMLName()
        {
            return "p";
        }

        public override bool isNewLine()
        {
            return true;
        }

        public override bool isNewParagraph()
        {
            return true;
        }

        /// <summary>
        /// 行距离左边的距离
        /// </summary>
        public int LeftChars
        {
            get
            {
                return base.myAttributes.GetInt32("leftchars");
            }
            set
            {
                base.myAttributes.SetValue("leftchars", (int)value);
            }
        }

        public override int Height
        {
            get
            {
                return base.Height;
            }
            set
            {
                base.Height = value;
            }
        }

        public override bool RefreshSize()
        {
            base.intWidth = 0;
            base.intHeight = base.myOwnerDocument.View.DefaultRowHeight();
            //if (base.OwnerDocument.IgnoreLine)
            //{
            //    if (base.myOwnerDocument.Info.Printing)
            //    {
            //        Printing();
            //    }
            //    else
            //    {
            //        if (this.Visible == false)
            //        {
            //            this.Deleteted = false;
            //        }
            //    }
            //}
            return true;
        }

        public void Printing()
        {
            if (this.Parent.Parent == null)
            {
                if (this.OwnerLine != null)
                    if (this.Parent is ZYTextDiv
                        && this.OwnerLine.Elements.Count == 1
                            )
                        if (this.OwnerLine.Elements[0] is ZYTextParagraph
                            && ((ZYTextDiv)this.Parent).RealLeft == 0)
                        {
                            if (this.Deleteted == false)
                            {
                                this.Visible = false;
                                this.Deleteted = true;
                            }
                        }
            }
        }

        public override bool RefreshView()
        {
            if (base.myOwnerDocument.Info.ShowParagraphFlag)
            {
                base.myOwnerDocument.View.DrawParagraphFlag(this.RealLeft, this.RealTop + this.Height);//段落标记
            }
            return true;
        }

        public override string ToZYString()
        {
            return "\r\n";
        }

        public ParagraphAlignConst Align
        {
            get
            {
                return (ParagraphAlignConst)base.myAttributes.GetInt32("align");
            }
            set
            {
                base.myAttributes.SetValue("align", (int)value);
            }
        }

        public bool CenterAlign
        {
            get
            {
                return (this.Align == ParagraphAlignConst.Center);
            }
            set
            {
                this.Align = ParagraphAlignConst.Center;
            }
        }

        public bool SkipPage
        {
            get
            {
                return base.myAttributes.GetBool("skip");
            }
            set
            {
                base.myAttributes.SetValue("skip", value);
            }
        }

        public bool SkipCreate
        {
            get
            {
                return base.myAttributes.GetBool("skipcreate");
            }
            set
            {
                base.myAttributes.SetValue("skip", value);
            }
        }

        public bool JustifyAlign
        {
            get
            {
                return (this.Align == ParagraphAlignConst.Justify);
            }
            set
            {
                this.Align = ParagraphAlignConst.Justify;
            }
        }

        public bool LeftAlign
        {
            get
            {
                return (this.Align == ParagraphAlignConst.Left);
            }
            set
            {
                this.Align = ParagraphAlignConst.Left;
            }
        }

        public bool RightAlign
        {
            get
            {
                return (this.Align == ParagraphAlignConst.Right);
            }
            set
            {
                this.Align = ParagraphAlignConst.Right;
            }
        }
    }
}

